home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5722 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  37 lines

  1. Newsgroups: comp.lang.c
  2. Path: ncrutr.Utrecht.NCR.COM!news
  3. From: Robert Luursema <RLuursem@wcnd.ns-nl.att.com>
  4. Subject: Re: How do I round and truncate floats to integers?
  5. Message-ID: <Dn2vz8.11s@ncrutr.Utrecht.NCR.COM>
  6. Sender: news@ncrutr.Utrecht.NCR.COM
  7. Reply-To: RLuursem@wcnd.ns-nl.att.com (ROBL)
  8. Organization: AT&T WCND
  9. X-Newsreader: DiscussIT 2.5.1.3 for MS Windows [AT&T Software Products Division]
  10. References: <fcusack-1502961821280001@mudskipper.cac.psu.edu>
  11. Date: Tue, 20 Feb 1996 14:23:31 GMT
  12.  
  13. > ==========frank., 96/02/15==========
  14. > typecasting will truncate. To round, add 0.5, then truncate (by
  15. > typecasting). Note that this is not "proper" rounding which
  16. changes which
  17. > way the rounding occurs if the decimal is exactly 0.5 depending
  18. > on whether the integer part is even or odd.
  19. > ie,  5.5 rounds to 6; but 4.5 rounds to 4
  20.  
  21. If your compiler behaves like this, you certainly have a problem
  22. (or a faulty pentium :-)
  23.  
  24.  
  25. > ~Frank
  26. >  -- I am Pentium of Borg.  Division is futile.  You will be
  27. > approximated. --
  28. >  --   If you build it, they will come -->
  29. > http://www.tdx.org/~fcusack/    --
  30. >  -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F  3F 64 80 65 8B
  31. > 0F F9 EA --
  32.  
  33.  
  34. Robert Luursema
  35. AT&T NWS Utrecht, the Netherlands
  36. rluursem@wcnd.utrecht.attgis.com
  37.